<?php

/** 
 * @author Boo
 * 
 */
class iDate {
	/**
	 * format type date time
	 * @param unknown $date
	 * @param unknown $n
	 * @return string
	 */
	public static function format($date, $n) {
		$t = '';
		switch ($n) {
			case 1 :
				$t = 'd-m-Y';
				break;
			case 2 :
				$t = 'Y-m-d';
				break;
		}
		return $date = date($t,strtotime($date));
	}
	/**
	 * add date by number
	 * @param unknown $date
	 * @param unknown $n
	 * @return string
	 */
	public static function add($date, $n) {
		$date = iDate::format($date, 1);
		return $date = date('d-m-Y',strtotime($date) + (24*3600*$n));
	}
	/**
	 * sub day by number
	 * @param unknown $date
	 * @param unknown $n
	 * @return string
	 */
	public static function sub($date, $n) {
		$date = iDate::format($date, 1);
		return $date = date('d-m-Y',strtotime($date) - (24*3600*$n));
	}
	/**
	 *  lay thoi diem hein tai
	 *  set zone tai diem = saigon 
	 * @return string
	 */
	public static function getNowdate(){
		date_default_timezone_set("asia/saigon");
		$date= getdate();
		$now= $date["year"].'-'.$date["mon"].'-'.$date["mday"].' '.$date['hours'].':'.$date['minutes'].':'.$date['seconds'];
		return $now;
	}
	/**
	 * so sanh voi ngay hien tai
	 * @param unknown $date
	 * @return boolean
	 */
	public static function comparenow($date){
		$now = iDate::getNowdate();
		if ($now < strtotime($date))
			return true;
		return false;
	}
	/**
	 * so sanh 2 ngay voi nhau
	 * @param unknown $datestart
	 * @param unknown $dateend
	 * @return boolean
	 */
	public static function compare($datestart,$dateend){
		if (strtotime($datestart) < strtotime($dateend))
			return true;
		return false;
	}
}

?>